import React from 'react';
import {Form, Row, Col, Button, DatePicker, message ,Divider,Input} from 'antd';
import { Link } from 'react-router-dom'
import {sessionManager} from '../../utils/sessionStorage';
import {injectIntl} from 'react-intl';
import Grid from '../../components/table/grid';
import axios from 'axios';
import moment from 'moment';
import SCSelect from '../../components/pickCity/SCSelect'

const FormItem = Form.Item;
const createForm = Form.create;

class CompanyManage extends React.Component {
    constructor(props) {
        super(props);
        this.common = this.props.intl.messages.common;
        this.columns = [
            {
                title: '企业编码',
                dataIndex: 'id',
                key: 'id',
                width:150
            },
            {
                title: '企业名',
                dataIndex: 'name',
                key: 'name',
                width:150
            },
            {
                title: '企业类型',
                dataIndex: 'type',
                key: 'type',
                width:100,
                render:(text)=>{
                    text==0?"个人":"企业"
                }
            },
            {
                title: '组织机构代码',
                dataIndex: 'orgCode',
                key: 'orgCode',
                width:120
            },
            {
                title: '身份证号码',
                dataIndex: 'idNo',
                key: 'idNo',
                width:150
            },
            {
                title: '管理员',
                dataIndex: 'chiefName',
                key: 'chiefName',
                width:120
            },
            {
                title: '星卡',
                width:120
            },
            {
                title: '短信',
                dataIndex: 'sendSms',
                key: 'sendSms',
                width:150
            },
            {
                title: '结算',
                dataIndex: 'settlementCnt',
                key: 'settlementCnt',
                width:150
               
            },
            {
                title: '用户数',
                dataIndex: 'userCnt',
                key: 'userCnt',
                width:80
            },
            {
                title: '星卡数',
                dataIndex: 'cardCnt',
                key: 'cardCnt',
                width:80
            },
            {
                title: '添加时间',
                dataIndex: 'createTime',
                key: 'createTime',
                width:180
            },
            {
                title: '状态',
                dataIndex: 'status',
                key: 'status',
                width:80
            },
            {
                title: this.common.operation,
                key: 'action',
                fixed: 'right',
                width:150,
                render: (text, record) => (
                    <span>
                        <a onClick={() => this.goLink(text, record, 'stub')}>电站</a>
                        <Divider type="vertical"/>
                        <a onClick={() => this.goLink(text, record, 'ecard')}>电卡</a>
                        <Divider type="vertical"/>
                        <a onClick={() => this.goLink(text, record, 'sms')}>短信</a>
                    </span>

                )
            }
        ];
        this.state = {
            refresh:0
        }
    }



    goLink = (text, record, link) => {
        // sessionManager.set('BillInfo', text);
        switch (link) {
            case 'stub':
                this.props.history.push({pathname: '/finance/BillDetails'});
                break;
            case 'adjust':
                this.setState({
                    visible: true,
                });
                console.log('adjust');
                break;
            default:
                this.props.history.push('/finance/orderDetails');
        }
    };



    handleSubmit = (e) => {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((errors, values) => {
            if (!!errors) {
                console.log('Errors in form!!!');
                return;
            }
            console.log(values);
            
        });
    }

    render() {
        const {getFieldDecorator} = this.props.form;
        const dateFormat = 'YYYY.MM.DD';
        return (
            <div>
                <form form={this.props.form} className={'SC-form'}>
                    <Row gutter={16} type="flex">
                        <Col xl={4} xxl={3}>
                            <FormItem
                            >
                                {getFieldDecorator('id')(
                                    <Input placeholder={'企业编码'}/>
                                )}
                            </FormItem>
                        </Col>
                        <Col xl={4} xxl={3}>
                            <FormItem
                            >
                                {getFieldDecorator('name')(
                                    <Input placeholder={'企业名'}/>
                                )}
                            </FormItem>
                        </Col>
                        <Col xl={4} xxl={3}>
                            <FormItem
                            >
                                {getFieldDecorator('account')(
                                    <Input placeholder={'管理员'}/>
                                )}
                            </FormItem>
                        </Col>
                        <Col xl={4} xxl={3}>
                            <FormItem
                            >
                                {getFieldDecorator('saasType')(
                                    <SCSelect url={()=>{return axios.post('/api/stubGroup/listForOption/qry')}} placeholder={"企业类型"}/>
                                )}
                            </FormItem>
                        </Col>
                        <Col xl={4} xxl={3}>
                            <FormItem
                            >
                                {getFieldDecorator('status')(
                                    <SCSelect data={[{"id":"1","name":"启用"},{"id":"2","name":"禁用"}]} placeholder={"状态"}/>
                                )}
                            </FormItem>
                        </Col>
                        <Col xl={4} xxl={3}>
                            <FormItem
                            >
                                {getFieldDecorator('settlementCnt')(
                                    <SCSelect data={[{"id":"0","name":"否"},{"id":"1","name":"是"}]} placeholder={"结算"}/>
                                )}
                            </FormItem>
                        </Col>
                    </Row>
                    <Row type="flex" justify="end">
                            <FormItem>
                                <Button className={"ant-btn-84"} type={'primary'} onClick={this.handleSubmit}>查询</Button>
                                <Button className={"ant-btn-84"}>导出</Button>
                                <Link to={"/company/AddCompany"}>
                                    <Button type={'primary'}>添加企业</Button>
                                </Link>
                            </FormItem>
                       
                    </Row>
                </form>
                <Grid url="/api/subCompany/corp/qry" columns={this.columns} refresh={this.state.refresh}/>
            </div>
        )
    }
}

CompanyManage = createForm()(CompanyManage);
export default injectIntl(CompanyManage)
